package com.lg.erp.controller.zhangchaofu;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lg.erp.entity.JsonResult;
import com.lg.erp.entity.zhangchaofu.Stock;
import com.lg.erp.service.zhangchaofu.IStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class StockController {

    @Autowired
    private IStockService stockService;

    @GetMapping("/stocks")
    public JsonResult getStockAll(@RequestParam(value = "current",required = false,defaultValue = "1") Integer current) {
        Page<Stock> page = new Page<>(current,10);
        IPage<Stock> stocks = stockService.findStockAll(page);
        for (Stock stock : stocks.getRecords()) {
            stock.setAvailableNum((Integer.parseInt(stock.getNNum()) - Integer.parseInt(stock.getPromiseNum()))+"");
        }
        return new JsonResult(1,"ok",stocks);

    }
    @GetMapping("/stockSearch")
    public JsonResult getSearch(String search,String current){
        System.out.println(search);
        System.out.println(current);

        List<Stock> stocks = stockService.findStockSearch(search);
        for (Stock stock : stocks) {
            stock.setAvailableNum((Integer.parseInt(stock.getNNum()) - Integer.parseInt(stock.getPromiseNum()))+"");
        }
        return new JsonResult(1,"ok",stocks);
    }

    @GetMapping("/stocksSub")
    public JsonResult getSub(String productNo,String wareId,String product){
        List<Stock> stocks = stockService.findStockSub(productNo,wareId,product);
        return new JsonResult(1,"ok",stocks);
    }

}
